package com.yyh.synctool.client.job;

import com.yyh.common.Common;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.Iterator;
import java.util.Map;

/**
 * @author xuan
 * @date 2021/12/16
 */
public class TestJob implements Job
{
    public static String taskId = TaskId.TEST;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String execTime = Common.currentTime();
        System.out.println("--------------------分隔线--------------------");
        System.out.println("执行测试任务，当前时间："+ execTime);

        JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
        Map<String, TaskInfo> tasks = (Map<String, TaskInfo>) dataMap.get("infos");
        TaskInfo info = tasks.get(taskId);

        System.out.println("任务信息集：");
        Iterator<String> iterator = tasks.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            System.out.println(key+" --> "+tasks.get(key));
        }
        System.out.println();

        info.setExecTime(execTime);
    }
}
